package com.shw.loco.adapter;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Date;

import android.os.Environment;

public class TestSourceThread extends Thread{
	
	public TestSourceThread(){
		newFile();
	}
	BufferedWriter bwe;
	private void newFile(){
		String pathString = Environment.getExternalStorageDirectory().getPath()
				+ "/shw_source_recore.TXT";
		File file=new File(pathString);
		
		/*if(!file.exists()){
			try {
				file.createNewFile();
				
			} catch (IOException e) {
			}
		}*/
		try {
			bwe=new BufferedWriter(new FileWriter(file,true));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		 
	}
	
	private void writeInfo(String info,BufferedWriter bws){
		try {
			bws.append(info+new Date().toGMTString()+"\n");
			bws.append("-------------------"+"\n");
			bws.flush();
		} catch (IOException e) {
		}
	}
	public void run(){
		while(!isInterrupted()){
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			if(LocoInfoQueue.sourceInfo.size()>0){
				writeInfo(LocoInfoQueue.sourceInfo.remove(0), bwe);
			}
			
		}
	}
}
